package com.xymtop.Service;

import com.xymtop.Entity.Stu;
import com.xymtop.Server.Util.Time;
import com.xymtop.Vo.StuVo;
import com.xymtop.Server.Util.DBService;

import java.util.List;

/**
 * @ClassName : StuService
 * @Description : 学生操作
 * @Author : 肖叶茂
 * @Date: 2022/12/12  18:28
 */
public class StuService {
    public StuVo login(String id, String password) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
      StuVo stu = new StuVo();

        List<Object> objs =  DBService.Get("select * from s_login where id = "+id+" and password = "+password, StuVo.class.getCanonicalName());
      if(objs.isEmpty()){
          return null;
      }else {
         return (StuVo) objs.get(0);
      }
    }

//    注册学生
    public Stu regist(Stu stu) throws ClassNotFoundException, InstantiationException, IllegalAccessException {

        if(stu.id == null){
            stu.setId(Time.getUnixTime());
        }
       Boolean flag = DBService.InsertObject(stu,"student");

        if(!flag){
            stu = null;
        }
        return  stu;
    }
}
